package com.mdp.structural.composite;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Composite implements IComponent {

    private List<IComponent> childNodeList = new ArrayList<IComponent>();

    @Override
    public void add(IComponent obj) {
        childNodeList.add(obj);
    }

    @Override
    public IComponent getChild(int index) {
        return (IComponent) childNodeList.get(index);
    }

    @Override
    public void operation() {
        System.out.println("++++++++++++" + this + "+++++++++++++");
        Iterator<IComponent> it = childNodeList.iterator();
        while (it.hasNext()) {
            ((IComponent) it.next()).operation();
        }
    }

    @Override
    public void remove(IComponent obj) {
        childNodeList.remove(obj);
    }

}
